package org.xc.studentssystem.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xc.studentssystem.mapper.UserManageSystemMapper;
import org.xc.studentssystem.pojo.User;

import java.util.List;

@RestController
public class UserManageSystemController {

    @Autowired
    private UserManageSystemMapper userManageSystemMapper;

    @RequestMapping("/getAllUser")
    public List<User> getAllUser(){
        //遍历所有用户的nick，如果是1则改为老师，2则改为管理员
        List<User> userList = userManageSystemMapper.getAllUser();
        for (User user : userList) {
            if (user.getNick().equals("1")){
                user.setNick("老师");
            }else if (user.getNick().equals("2")){
                user.setNick("管理员");
            }
        }
        return userList;
    }

    @RequestMapping("/deleteUser")
    public String deleteUser(@RequestBody User user){
        userManageSystemMapper.deleteUser(user);
        return "success";
    }

    @RequestMapping("/selectform")
    public User selectform(@RequestBody User user){
        return userManageSystemMapper.selectform(user);
    }

    @RequestMapping("/updataUser")
    public void updateUser(@RequestBody User user){
        userManageSystemMapper.updateUser(user);
    }

    @RequestMapping("/getUserByName")
    public User getUserById(@RequestBody User user){
        return userManageSystemMapper.getUserByName(user);
    }



}
